package com.oplink.webems.common.snmp;

import java.util.HashMap;
import java.util.Map;

import com.oplink.webems.common.snmp.entity.Card;
import com.oplink.webems.common.snmp.entity.Dcp22Card;
import com.oplink.webems.common.snmp.entity.Dcp2Card;
import com.oplink.webems.common.snmp.entity.SccCard;
import com.oplink.webems.modules.cfg.entity.CfgCard;

/**
 * 将数据库对象映射成通讯数据对象
 * 
 * @author yongz
 * 
 */
public class CardParser {

	public static final Map<Integer, String> cardTypeMap = new HashMap<Integer, String>() {
		private static final long serialVersionUID = 4835212516473751973L;
		{
			put(Dcp2Card.CARDTYPE, Dcp2Card.class.getCanonicalName());
			put(Dcp22Card.CARDTYPE, Dcp22Card.class.getCanonicalName());
			put(SccCard.CARDTYPE, SccCard.class.getCanonicalName());
		}
	};

	/**
	 * 数据库对象转化成通讯对象
	 * 
	 * @param c
	 * @return
	 */
	public static Card toSnmpCard(CfgCard c) {
		Card card;

		int cardType = Integer.parseInt(c.getType());
		int slot = c.getSlot();
		int chassis = 1;

		try {
			card = (Card) Class.forName(cardTypeMap.get(cardType)).getConstructor(Integer.class, Integer.class)
					.newInstance(chassis, slot);
			card.setCardType(cardType);
			card.setSlot(slot);
			card.setChassis(1);
			return card;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String[] args) {
		// System.out.println(Dcp2Card.class.getCanonicalName());
		try {
			Class.forName("com.oplink.webems.common.snmp.entity.Dcp2Card").getConstructor(Integer.class, Integer.class)
					.newInstance(1, 5);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
